﻿Imports QLTHUVIEN.BUS
Imports QLTHUVIEN.DAO
Imports QLTHUVIEN.DTO

Public Class frmChucVu

    Private Sub layDanhSach()
        Dim ChucVuBus As ChucVuBUS = New ChucVuBUS()
        Dim data As DataTable = ChucVuBus.LayDanhSach()
        dtgDanhSachChucVu.DataSource = data
    End Sub

    Private Sub frmChucVu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        layDanhSach()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If txtTenChucVu.Text = "" Then
            Return
        End If

        Dim ChucVuDto As New ChucVuDTO()
        ChucVuDto.TenChucVu = txtTenChucVu.Text

        Dim cvBus As New ChucVuBUS()
        cvBus.ThemChucVu(ChucVuDto)

        layDanhSach()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If txtTenChucVu.Text = "" Or txtMaChucVu.Text = "" Then
            Return
        End If

        Dim ChucVuDto As New ChucVuDTO()
        ChucVuDto.MaChucVu = txtMaChucVu.Text
        ChucVuDto.TenChucVu = txtTenChucVu.Text

        Dim cvBus As New ChucVuBUS()
        cvBus.SuaChucVu(ChucVuDto)

        layDanhSach()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        If txtTenChucVu.Text = "" Or txtMaChucVu.Text = "" Then
            Return
        End If

        Dim ChucVuDto As New ChucVuDTO()
        ChucVuDto.MaChucVu = txtMaChucVu.Text
        ChucVuDto.TenChucVu = txtTenChucVu.Text
        ChucVuDto.IsDelete = True

        Dim cvBus As New ChucVuBUS()
        cvBus.XoaChucVu(ChucVuDto)

        layDanhSach()
    End Sub

    Private Sub dtgDanhSachChucVu_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgDanhSachChucVu.CellClick
        txtMaChucVu.Text = dtgDanhSachChucVu.CurrentRow.Cells(0).Value.ToString()
        txtTenChucVu.Text = dtgDanhSachChucVu.CurrentRow.Cells(1).Value.ToString()
    End Sub
End Class